package collection;

import java.util.Deque;
import java.util.LinkedList;

/**
 *  双端队列
 *  java.util.Deque接口,双端队列是队列两端都可以做出入队的队列.
 *  Deque继承自Queue,常用实现类:LinkedList
 */
public class DequeDemo {
    public static void main(String[] args) {
        Deque<String> deque = new LinkedList<>();
        deque.offer("one");
        deque.offer("two");
        deque.offer("three");
        System.out.println(deque);

        //队首入队
        deque.offerFirst("seven");
        System.out.println(deque);

        //队尾入队,与offer一致
        deque.offerLast("four");
        System.out.println(deque);

        System.out.println(deque.poll());
        System.out.println(deque);

        //队首出队
        System.out.println(deque.pollFirst());
        System.out.println(deque);

        //队尾出队
        System.out.println(deque.pollLast());
        System.out.println(deque);
    }
}